import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;


public class MeetingAgentTest extends MIDlet implements CommandListener, ItemStateListener 
{
	private Display display;
	private Form form;
	private Command cmExit,good,good2,good3,back1,back2,back3,confirm;
	private StringItem str;
	private DateField dfDate; //display the date
	
	private TextField field,dateField1,dateField2,dateField3;
	
	public MeetingAgentTest() {
		
		display= Display.getDisplay(this);
		
		//create date and populate it
		dfDate = new DateField("Date is:",DateField.DATE);
		//java utility for displaying the calendar
		dfDate.setDate(new java.util.Date());
		
		str= new StringItem("choose a date", null);
		cmExit = new Command("Exit",Command.EXIT,1);
		good = new Command("Continue",Command.SCREEN,2);
		back1 = new Command("back",Command.SCREEN,2);
		good2 = new Command("Continue",Command.SCREEN,3);
		back2 = new Command("back",Command.SCREEN,2);
		good3 = new Command("Continue",Command.SCREEN,4);
		back3 = new Command("back",Command.SCREEN,2);
		confirm = new Command("confirm",Command.SCREEN,2);
		
	    field = new TextField("Meeting Duration(in hrs)", "",10,TextField.DECIMAL);
	    dateField1 = new TextField("Times you are available(24 HR)\n 1", "",10,TextField.DECIMAL);
	    dateField2 = new TextField("2", "",10,TextField.DECIMAL);
	    dateField3 = new TextField("3", "",10,TextField.DECIMAL);
		form = new Form("Meeting Agent");
		form.addCommand(cmExit);
		form.addCommand(good);
		
		form.append(str);
		form.append(dfDate);
		
		form.setCommandListener( this);
		
		form.setItemStateListener(this);
	}

	protected void destroyApp(boolean arg0)  {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		display.setCurrent(form);
	}

	public void commandAction(Command c, Displayable s) 
	{
		// TODO Auto-generated method stub
		if(c == cmExit)
		{
			
			destroyApp(false);
			notifyDestroyed();
		}else if ((c == good)||(c == back1)){
			form.deleteAll();
			form.append(field);
			
			form.addCommand(good2);
			form.addCommand(cmExit);
			form.removeCommand(good);
		}else if ((c == good2)||(c == back2)){
			form.deleteAll();
			form.append(dateField1);
			form.append(dateField2);
			form.append(dateField3);
			form.addCommand(good3);
			form.removeCommand(good2);
			form.addCommand(back1);
		}else if(c == good3){
			
			form.deleteAll();
			
			StringItem str= new StringItem("Your times are:\n",dateField1.getString()+" \n"+ dateField2.getString()
					+"\n"+dateField3.getString());
			form.append(str);
			form.removeCommand(back1);
			form.removeCommand(good3);
			form.addCommand(back2);
			form.addCommand(confirm);
		}else if(c == confirm){
			form.deleteAll();
			StringItem str2= new StringItem("Sending agent...",null);
			form.append(str2);
			
		}
	}

	
		public void itemStateChanged(Item item) {
			// TODO Auto-generated method stub
			dfDate.setLabel("Meeting Date is ");
		}
	

}
